package com.jiazhong;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan(basePackages = "com.jiazhong.dao")
public class SpringbootProServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringbootProServerApplication.class, args);
	}

	/***
	 * 跨域配置
	 * 
	 * @return
	 */
	@Bean
	public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurer() {
			/*
			 * 添加跨域访问映射路径
			 */
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/**")// 允许跨域访问当前项目的所有路径
						.allowCredentials(true)// 是否允许使用凭证(session)
						.allowedMethods("*");// 设置跨域访问的请求为任意请求
			}
		};
	}
}
